<template>
  <div>
     <div class="config">
      <p>个人中心</p>
    </div>
     <div class="header">
          <img :src="icon_url" alt="" id="img">
          <input type="file" class="file" id="file" @change="change()">

          <p>{{name}}</p>
          <router-link to="/accountManagement">
            <span>账户管理</span>
          </router-link>
     </div>
     <div class="box">
        <router-link to="/myWallet">
              <div class="row">
                <img src="../assets/images/wodeqianbao.png" alt="" class="img">
                <p>我的钱包</p>
                <img src="../assets/images/gd.png" alt="" class="gengduo">
              </div>
        </router-link>
        <router-link to="/consumeRecord">
              <div class="row">
                <img src="../assets/images/xiaofeijilu.png" alt="" class="img">
                <p>消费记录</p>
                <img src="../assets/images/gd.png" alt="" class="gengduo">
              </div>
        </router-link>
           <router-link to="/inviteFriends">
              <div class="row">
                <img src="../assets/images/yaoqingxindaili.png" alt="" class="img">
                <p>邀请新代理</p>
                <img src="../assets/images/gd.png" alt="" class="gengduo">
              </div>
        </router-link>
           <router-link to="/message">
              <div class="row">
                <img src="../assets/images/xiaoxi.png" alt="" class="img">
                <p>消息</p>
                <img src="../assets/images/gd.png" alt="" class="gengduo">
              </div>
        </router-link>
           <router-link to="/myServices">
              <div class="row">
                <img src="../assets/images/wodefuwu.png" alt="" class="img">
                <p>我的服务</p>
                <img src="../assets/images/gd.png" alt="" class="gengduo">
              </div>
        </router-link>
                 <router-link to="/certificate">
              <div class="row">
                <img src="../assets/images/zhengshu_.png" alt="" class="img">
                <p>我的证书</p>
                <img src="../assets/images/gd.png" alt="" class="gengduo">
              </div>
        </router-link>

      <div class="btn">
        <button>退出登录</button>
      </div>

            <!-- 底部tab -->
    <div class="tab">
      <ul>
          <router-link to="/personal">
          <li><img src="../assets/images/gerenzhongxin_.png" alt="">
            <p>个人中心</p>
          </li>
        </router-link>
        <router-link to="/rakeBack">
          <li><img src="../assets/images/fanyong.png" alt="">
            <p>返佣</p>
          </li>
        </router-link>
      
      </ul>
    </div>

       
     </div>


  </div>
</template>

<script>
export default {
    name: "personal",
    data() {
        return {
            name: "",
            icon_url: ""
        };
    },
    beforeCreate() {
        document.getElementsByTagName("body")[0].style.background = "#eaeaea";
    },
    methods: {
        // 查询信息
        select() {
            var qs=require("qs");
            this.axios({
                method: "post",
                url: `${this.siteUrl}/getUser`,
                data: qs.stringify({
                    uid: localStorage.getItem("uid")
                })
            })
                .then(response => {
                   
                    if (response.data.result == 200) {
                        var data = response.data.data;
                        this.name = data.name;
                        this.icon_url = data.icon_url;
                        localStorage.setItem("uid", data.uid);
                        localStorage.setItem("icon_url", this.icon_url);
                        localStorage.setItem("mylevel", data.level);
                        localStorage.setItem("name",data.name);
                        
                        
                    } else {
                        alert("请求失败");
                    }
                })
                .catch(function(error) {
                    console.log(error);
                });
        },
        change() {
            var file = document.getElementById("file").files[0];
            var url = URL.createObjectURL(file);
            document.getElementById("img").src = url;
            var param = new FormData();
            param.append("uid", localStorage.getItem("uid"));
            param.append("file", file);

            this.axios({
                method: "post",
                url: `${this.siteUrl}/setIcon`,
                data: param
            })
                .then(response => {
                  
                    if ((response.data.result == 200)) {
                        this.$Message.success(response.data.message);
                        this.select();
                    } else {
                        alert("请求失败");
                    }
                })
                .catch(function(error) {
                    console.log(error);
                });
        }
    },
    mounted() {
        this.select();
    }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.header {
    width: 100%;
    height: 45vh;
    background: #5aa0c8;
    text-align: center;
}
.header img {
    width: 100px;
    height: 100px;
    border-radius: 50px;
    margin-top: 8vh;
}
.header .file {
    position: absolute;
    width: 100px;
    height: 100px;
    border-radius: 50px;
    margin-top: 8vh;
    margin-left: -100px;
    opacity: 0;
}
.header p {
    margin-top: 5px;
    color: #fff;
}
.header span {
    position: absolute;
    right: 20px;
    top: 70px;
    box-shadow: 0px 0px 1px 1px #f7f7f7;
    padding: 3px 10px;
    border-radius: 2px;
    color: #fff;
}

.box {
    width: 94%;
    margin-left: 3%;
    border-radius: 3px;
    margin-top: -50px;
    box-shadow: 0px 0px 1px 1px #ccc;
    background: #fff;
    margin-bottom: 70px;
}

.row {
    height: 50px;
    background: #fff;
    position: relative;
    border-bottom: 1px solid #f2f2f2;
    margin: 8px;
}

.row .img {
    position: absolute;
    width: 22px;
    top: 13px;
    left: 5px;
}

.row .gengduo {
    position: absolute;
    height: 12px;
    top: 19px;
    right: 5px;
}

.row p {
    position: absolute;
    left: 40px;
    top: 15px;
    font-size: 14px;
}

.btn {
    width: 100%;
    padding-bottom: 20px;
}

.btn button {
    width: 90%;
    height: 50px;
    background: #5aa0c8;
    border: none;
    color: #fff;
    outline: none;
    margin-left: 5%;
    margin-top: 20px;
    border-radius: 5px;
}

/* 底部tab */

.tab {
    width: 100%;
    height: 50px;
    position: fixed;
    bottom: 0px;
    left: 0px;
    border-top: 1px solid #ddd;
    background: #fff;
}

.tab ul li {
    width: 50%;
    float: left;
    text-align: center;
}

.tab ul li img {
    width: 20px;
    height: 25px;
    padding-top: 5px;
}

.tab ul li p {
    font-size: 12px;
    color: #666;
}

.tab ul li p.active {
    color: #5aa0c8;
}
</style>
